<template>
  <div>
    <el-form
      class="detail-form-content"
      ref="ruleForm"
      :model="ruleForm"
      label-width="80px"
    >  
     <el-row>
                    <el-col :span="12">
           <el-form-item v-if="flag=='dabianmishu'"  label='答辩秘书姓名' prop="dabianmishuName">
               <el-input v-model="ruleForm.dabianmishuName"  placeholder='答辩秘书姓名' clearable></el-input>
           </el-form-item>
         </el-col>

         <el-col :span="12">
             <el-form-item v-if="flag=='dabianmishu'" label='头像' prop="dabianmishuPhoto">
                 <file-upload
                         tip="点击上传照片"
                         action="file/upload"
                         :limit="3"
                         :multiple="true"
                         :fileUrls="ruleForm.dabianmishuPhoto?ruleForm.dabianmishuPhoto:''"
                         @change="dabianmishuPhotoUploadChange"
                 ></file-upload>
             </el-form-item>
         </el-col>
         <el-col :span="12">
           <el-form-item v-if="flag=='dabianmishu'"  label='联系方式' prop="dabianmishuPhone">
               <el-input v-model="ruleForm.dabianmishuPhone"  placeholder='联系方式' clearable></el-input>
           </el-form-item>
         </el-col>

         <el-col :span="12">
           <el-form-item v-if="flag=='dabianmishu'"  label='邮箱' prop="dabianmishuEmail">
               <el-input v-model="ruleForm.dabianmishuEmail"  placeholder='邮箱' clearable></el-input>
           </el-form-item>
         </el-col>

         <el-col :span="12">
           <el-form-item v-if="flag=='pingyuejiaoshi'"  label='评阅教师姓名' prop="pingyuejiaoshiName">
               <el-input v-model="ruleForm.pingyuejiaoshiName"  placeholder='评阅教师姓名' clearable></el-input>
           </el-form-item>
         </el-col>

         <el-col :span="12">
             <el-form-item v-if="flag=='pingyuejiaoshi'" label='头像' prop="pingyuejiaoshiPhoto">
                 <file-upload
                         tip="点击上传照片"
                         action="file/upload"
                         :limit="3"
                         :multiple="true"
                         :fileUrls="ruleForm.pingyuejiaoshiPhoto?ruleForm.pingyuejiaoshiPhoto:''"
                         @change="pingyuejiaoshiPhotoUploadChange"
                 ></file-upload>
             </el-form-item>
         </el-col>
         <el-col :span="12">
           <el-form-item v-if="flag=='pingyuejiaoshi'"  label='联系方式' prop="pingyuejiaoshiPhone">
               <el-input v-model="ruleForm.pingyuejiaoshiPhone"  placeholder='联系方式' clearable></el-input>
           </el-form-item>
         </el-col>

         <el-col :span="12">
           <el-form-item v-if="flag=='pingyuejiaoshi'"  label='邮箱' prop="pingyuejiaoshiEmail">
               <el-input v-model="ruleForm.pingyuejiaoshiEmail"  placeholder='邮箱' clearable></el-input>
           </el-form-item>
         </el-col>

         <el-col :span="12">
           <el-form-item v-if="flag=='yonghu'"  label='学号' prop="yonghuUuidNumber">
               <el-input v-model="ruleForm.yonghuUuidNumber"  placeholder='学号' clearable></el-input>
           </el-form-item>
         </el-col>

         <el-col :span="12">
           <el-form-item v-if="flag=='yonghu'"  label='用户姓名' prop="yonghuName">
               <el-input v-model="ruleForm.yonghuName"  placeholder='用户姓名' clearable></el-input>
           </el-form-item>
         </el-col>

         <el-col :span="12">
             <el-form-item v-if="flag=='yonghu'" label='头像' prop="yonghuPhoto">
                 <file-upload
                         tip="点击上传照片"
                         action="file/upload"
                         :limit="3"
                         :multiple="true"
                         :fileUrls="ruleForm.yonghuPhoto?ruleForm.yonghuPhoto:''"
                         @change="yonghuPhotoUploadChange"
                 ></file-upload>
             </el-form-item>
         </el-col>
         <el-col :span="12">
           <el-form-item v-if="flag=='yonghu'"  label='联系方式' prop="yonghuPhone">
               <el-input v-model="ruleForm.yonghuPhone"  placeholder='联系方式' clearable></el-input>
           </el-form-item>
         </el-col>

         <el-col :span="12">
           <el-form-item v-if="flag=='yonghu'"  label='邮箱' prop="yonghuEmail">
               <el-input v-model="ruleForm.yonghuEmail"  placeholder='邮箱' clearable></el-input>
           </el-form-item>
         </el-col>

         <el-col :span="12">
             <el-form-item v-if="flag=='yonghu'"  label='专业' prop="xuekeTypes">
                 <el-select v-model="ruleForm.xuekeTypes"  placeholder='请选择专业'>
                     <el-option
                             v-for="(item,index) in xuekeTypesOptions"
                             v-bind:key="item.codeIndex"
                             :label="item.indexName"
                             :value="item.codeIndex">
                     </el-option>
                 </el-select>
             </el-form-item>
         </el-col>
         <el-col :span="12">
             <el-form-item v-if="flag=='yonghu'"  label='班级' prop="banjiTypes">
                 <el-select v-model="ruleForm.banjiTypes"  placeholder='请选择班级'>
                     <el-option
                             v-for="(item,index) in banjiTypesOptions"
                             v-bind:key="item.codeIndex"
                             :label="item.indexName"
                             :value="item.codeIndex">
                     </el-option>
                 </el-select>
             </el-form-item>
         </el-col>
         <el-col :span="12">
           <el-form-item v-if="flag=='zhidaojiaoshi'"  label='指导教师姓名' prop="zhidaojiaoshiName">
               <el-input v-model="ruleForm.zhidaojiaoshiName"  placeholder='指导教师姓名' clearable></el-input>
           </el-form-item>
         </el-col>

         <el-col :span="12">
             <el-form-item v-if="flag=='zhidaojiaoshi'" label='头像' prop="zhidaojiaoshiPhoto">
                 <file-upload
                         tip="点击上传照片"
                         action="file/upload"
                         :limit="3"
                         :multiple="true"
                         :fileUrls="ruleForm.zhidaojiaoshiPhoto?ruleForm.zhidaojiaoshiPhoto:''"
                         @change="zhidaojiaoshiPhotoUploadChange"
                 ></file-upload>
             </el-form-item>
         </el-col>
         <el-col :span="12">
           <el-form-item v-if="flag=='zhidaojiaoshi'"  label='联系方式' prop="zhidaojiaoshiPhone">
               <el-input v-model="ruleForm.zhidaojiaoshiPhone"  placeholder='联系方式' clearable></el-input>
           </el-form-item>
         </el-col>

         <el-col :span="12">
           <el-form-item v-if="flag=='zhidaojiaoshi'"  label='邮箱' prop="zhidaojiaoshiEmail">
               <el-input v-model="ruleForm.zhidaojiaoshiEmail"  placeholder='邮箱' clearable></el-input>
           </el-form-item>
         </el-col>

         <el-form-item v-if="flag=='users'" label="用户名" prop="username">
             <el-input v-model="ruleForm.username"
                       placeholder="用户名"></el-input>
         </el-form-item>
         <el-col :span="12">
             <el-form-item v-if="flag!='users'"  label="性别" prop="sexTypes">
                 <el-select v-model="ruleForm.sexTypes" placeholder="请选择性别">
                     <el-option
                             v-for="(item,index) in sexTypesOptions"
                             v-bind:key="item.codeIndex"
                             :label="item.indexName"
                             :value="item.codeIndex">
                     </el-option>
                 </el-select>
             </el-form-item>
         </el-col>
         <el-col :span="24">
             <el-form-item>
                 <el-button type="primary" @click="onUpdateHandler">修 改</el-button>
             </el-form-item>
         </el-col>
     </el-row>
    </el-form>
  </div>
</template>
<script>
// 数字，邮件，手机，url，身份证校验
import { isNumber,isIntNumer,isEmail,isMobile,isPhone,isURL,checkIdCard } from "@/utils/validate";

export default {
  data() {
    return {
        ruleForm: {},
        flag: '',
        usersFlag: false,
        // sexTypesOptions : [],
// 注册表 用户
    // 注册的类型字段 用户
        // 性别
        sexTypesOptions : [],
        // 专业
        xuekeTypesOptions : [],
        // 班级
        banjiTypesOptions : [],
// 注册表 评阅教师
    // 注册的类型字段 评阅教师
        // 性别
        sexTypesOptions : [],
// 注册表 答辩秘书
    // 注册的类型字段 答辩秘书
        // 性别
        sexTypesOptions : [],
// 注册表 指导教师
    // 注册的类型字段 指导教师
        // 性别
        sexTypesOptions : [],
    };
  },
  mounted() {
    //获取当前登录用户的信息
    var table = this.$storage.get("sessionTable");
    this.sessionTable = this.$storage.get("sessionTable");
    this.role = this.$storage.get("role");
    if (this.role != "管理员"){
    }

    this.flag = table;
    this.$http({
      url: `${this.$storage.get("sessionTable")}/session`,
      method: "get"
    }).then(({ data }) => {
      if (data && data.code === 0) {
        this.ruleForm = data.data;
// 注册表 用户
// 注册表 评阅教师
// 注册表 答辩秘书
// 注册表 指导教师
      } else {
        this.$message.error(data.msg);
      }
    });

// 注册表 用户 的级联表
// 注册表 评阅教师 的级联表
// 注册表 答辩秘书 的级联表
// 注册表 指导教师 的级联表

      this.$http({
          url: `dictionary/page?page=1&limit=100&sort=&order=&dicCode=sex_types`,
          method: "get"
      }).then(({ data }) => {
          if (data && data.code === 0) {
              this.sexTypesOptions = data.data.list;
          } else {
              this.$message.error(data.msg);
          }
      });
   this.$http({
       url: `dictionary/page?page=1&limit=100&sort=&order=&dicCode=xueke_types`,
       method: "get"
   }).then(({ data }) => {
       if (data && data.code === 0) {
          this.xuekeTypesOptions = data.data.list;
      } else {
          this.$message.error(data.msg);
      }
    });
   this.$http({
       url: `dictionary/page?page=1&limit=100&sort=&order=&dicCode=banji_types`,
       method: "get"
   }).then(({ data }) => {
       if (data && data.code === 0) {
          this.banjiTypesOptions = data.data.list;
      } else {
          this.$message.error(data.msg);
      }
    });
  },
  methods: {
    chongzhi() {
      this.$router.replace({ path: "/pay" });
    },
    dabianmishuPhotoUploadChange(fileUrls) {
        this.ruleForm.dabianmishuPhoto = fileUrls;
    },
    pingyuejiaoshiPhotoUploadChange(fileUrls) {
        this.ruleForm.pingyuejiaoshiPhoto = fileUrls;
    },
    yonghuPhotoUploadChange(fileUrls) {
        this.ruleForm.yonghuPhoto = fileUrls;
    },
    zhidaojiaoshiPhotoUploadChange(fileUrls) {
        this.ruleForm.zhidaojiaoshiPhoto = fileUrls;
    },


    onUpdateHandler() {
                         if((!this.ruleForm.dabianmishuName)&& 'dabianmishu'==this.flag){
                             this.$message.error('答辩秘书姓名不能为空');
                             return
                         }

                         if((!this.ruleForm.dabianmishuPhoto)&& 'dabianmishu'==this.flag){
                             this.$message.error('头像不能为空');
                             return
                         }

                         if((!this.ruleForm.dabianmishuPhone)&& 'dabianmishu'==this.flag){
                             this.$message.error('联系方式不能为空');
                             return
                         }

                             if( 'dabianmishu' ==this.flag && this.ruleForm.dabianmishuEmail&&(!isEmail(this.ruleForm.dabianmishuEmail))){
                                 this.$message.error(`邮箱应输入邮箱格式`);
                                 return
                             }
                         if((!this.ruleForm.pingyuejiaoshiName)&& 'pingyuejiaoshi'==this.flag){
                             this.$message.error('评阅教师姓名不能为空');
                             return
                         }

                         if((!this.ruleForm.pingyuejiaoshiPhoto)&& 'pingyuejiaoshi'==this.flag){
                             this.$message.error('头像不能为空');
                             return
                         }

                         if((!this.ruleForm.pingyuejiaoshiPhone)&& 'pingyuejiaoshi'==this.flag){
                             this.$message.error('联系方式不能为空');
                             return
                         }

                             if( 'pingyuejiaoshi' ==this.flag && this.ruleForm.pingyuejiaoshiEmail&&(!isEmail(this.ruleForm.pingyuejiaoshiEmail))){
                                 this.$message.error(`邮箱应输入邮箱格式`);
                                 return
                             }
                         if((!this.ruleForm.yonghuUuidNumber)&& 'yonghu'==this.flag){
                             this.$message.error('学号不能为空');
                             return
                         }

                         if((!this.ruleForm.yonghuName)&& 'yonghu'==this.flag){
                             this.$message.error('用户姓名不能为空');
                             return
                         }

                         if((!this.ruleForm.yonghuPhoto)&& 'yonghu'==this.flag){
                             this.$message.error('头像不能为空');
                             return
                         }

                         if((!this.ruleForm.yonghuPhone)&& 'yonghu'==this.flag){
                             this.$message.error('联系方式不能为空');
                             return
                         }

                             if( 'yonghu' ==this.flag && this.ruleForm.yonghuEmail&&(!isEmail(this.ruleForm.yonghuEmail))){
                                 this.$message.error(`邮箱应输入邮箱格式`);
                                 return
                             }
                         if((!this.ruleForm.xuekeTypes)&& 'yonghu'==this.flag){
                             this.$message.error('专业不能为空');
                             return
                         }

                         if((!this.ruleForm.banjiTypes)&& 'yonghu'==this.flag){
                             this.$message.error('班级不能为空');
                             return
                         }

                         if((!this.ruleForm.zhidaojiaoshiName)&& 'zhidaojiaoshi'==this.flag){
                             this.$message.error('指导教师姓名不能为空');
                             return
                         }

                         if((!this.ruleForm.zhidaojiaoshiPhoto)&& 'zhidaojiaoshi'==this.flag){
                             this.$message.error('头像不能为空');
                             return
                         }

                         if((!this.ruleForm.zhidaojiaoshiPhone)&& 'zhidaojiaoshi'==this.flag){
                             this.$message.error('联系方式不能为空');
                             return
                         }

                             if( 'zhidaojiaoshi' ==this.flag && this.ruleForm.zhidaojiaoshiEmail&&(!isEmail(this.ruleForm.zhidaojiaoshiEmail))){
                                 this.$message.error(`邮箱应输入邮箱格式`);
                                 return
                             }
        if((!this.ruleForm.sexTypes) && this.flag!='users'){
            this.$message.error('性别不能为空');
            return
        }
      if('users'==this.flag && this.ruleForm.username.trim().length<1) {
        this.$message.error(`用户名不能为空`);
        return	
      }
      this.$http({
        url: `${this.$storage.get("sessionTable")}/update`,
        method: "post",
        data: this.ruleForm
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.$message({
            message: "修改信息成功",
            type: "success",
            duration: 1500,
            onClose: () => {
            }
          });
        } else {
          this.$message.error(data.msg);
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
</style>
